# -*- coding:utf-8 -*-

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.linear_model import LinearRegression,SGDRegressor,Ridge
from sklearn.metrics import mean_squared_error
import joblib
import sys

sys.path.append("../")
from frameworks.utils.PadasExcelUtil import *
import warnings
warnings.filterwarnings('ignore')

def main():
    data = pd.read_csv("H:/model/score.txt", encoding="utf-8", sep='\t')
    df = data.dropna()
    print("特征数量：\n", df.shape)

    newdf = df[['flow_money',"score","money_score","zf"]]
    print(newdf)

    # 2）划分数据集
    x_train, x_test, y_train, y_test = train_test_split(newdf, df["rs_zf"], random_state=22)
    print(x_test)
    # 2、标准化处理

    # 特征值处理
    std_x = StandardScaler()
    x_train = std_x.fit_transform(x_train)
    x_test = std_x.transform(x_test)

    # 3、估计器流程

    # LinearRegression
    lr = LinearRegression()

    lr.fit(x_train, y_train)

    # print(lr.coef_)

    y_lr_predict = lr.predict(x_test)

    print("Lr预测值：", y_lr_predict)

    # SGDRegressor
    sgd = SGDRegressor()

    sgd.fit(x_train, y_train)

    # print(sgd.coef_)

    y_sgd_predict = sgd.predict(x_test)

    print("SGD预测值：", y_sgd_predict)

    # 带有正则化的岭回归

    rd = Ridge(alpha=0.01)

    rd.fit(x_train, y_train)

    y_rd_predict = rd.predict(x_test)

    print(rd.coef_)

    # 两种模型评估结果

    print("lr的均方误差为：", mean_squared_error(y_test, y_lr_predict))

    print("SGD的均方误差为：", mean_squared_error(y_test, y_sgd_predict))

    print("Ridge的均方误差为：", mean_squared_error(y_test, y_rd_predict))

    return None

if __name__ == "__main__":
    main()